import {IStateModule} from 'rpc_dream_server';

export class StateModuleLocalStorageImplementation implements  IStateModule {
    public clientId: string = ""
    public constructor (public namespace: string, private canBePrintLog = false){

    }
    async getStateKey(): Promise<string> {
        if (this.canBePrintLog) console.log("Get state key")
        let  key = localStorage.getItem(`${this.namespace}/keyOfState`)
        if (key == null) key = ""
        this.clientId = key
        return key
    }
    async setStateKey(key: string): Promise<void> {
        if (this.canBePrintLog) console.log("Set state key")
        localStorage.setItem(`${this.namespace}/keyOfState`, key)
        this.clientId = key
    }
    async stateRestored(key: string): Promise<void> {
        if (this.canBePrintLog) console.log("State restored")
        this.clientId = key
    }
}
